package com.kc.stand.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kc.stand.domain.FileRecord;
import com.kc.stand.domain.FileRecord;
import com.kc.stand.service.FileRecordService;
import com.kc.stand.vo.FileRecordVo;
import com.kc.stand.vo.FileRecordVo;
import com.kc.sys.common.DataGridView;
import com.kc.sys.domain.Station;
import com.kc.sys.domain.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *  修改记录控制器
 * @author 老杜
 * @since 2020-01-13
 */
@RestController
@RequestMapping("/standFileRecord")
public class FileRecordController {


    @Autowired
    private FileRecordService fileRecordService;

    /**
     * 查询
     */
    @RequestMapping("loadAllStandFileRecordList")
    public DataGridView loadAllStandFileRecordList(FileRecordVo fileRecordVo){
        //获取用户session
        //User user = (User)WebUtils.getSession().getAttribute("user");
        IPage<FileRecord> page = new Page<>(fileRecordVo.getPage(),fileRecordVo.getLimit());
        QueryWrapper<FileRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(fileRecordVo.getArticleTitle()),"article_title",fileRecordVo.getArticleTitle());
        fileRecordService.page(page,queryWrapper);
        List<FileRecord> records = page.getRecords();
        for (FileRecord record : records) {
           /* if(null!=record.getSid()){
                Station station = stationService.getById(record.getSid());
                record.setStationName(station.getTitle());
            }
            if (null!=record.getModifyPerson()){
                User user = userService.getById(record.getModifyPerson());
                record.setModifyPersonName(user.getName());
            }*/
        }
        return new DataGridView(page.getTotal(),page.getRecords());
    }
}

